<%--
  Created by IntelliJ IDEA.
  User: lt
  Date: 2018/6/21
  Time: 21:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<title>商品移库</title>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jquery-ui/jquery-ui.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.css"/>
<link rel="stylesheet" href="${contextPath}/static/ace/components/_mod/jqgrid/ui.jqgrid.css"/>
<%--  <jsp:include page="../../head.jsp"/>   --%> 
<link rel="stylesheet" href="${contextPath}/static/bootstrap/css/bootstrap-select.css" />
<link rel="stylesheet" href="${contextPath}/static/ztree/css/zTreeStyle.css" />
<script src="${contextPath}/static/bootstrap/js/bootstrap-select.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.min.js"></script>
<script src="${contextPath}/static/statistics/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="${contextPath}/static/statistics/js/vue.js"></script>
<script src=${contextPath}/static/layer/layui.all.js></script>
<script src="${contextPath}/static/countjs/regularYz.js"></script>
<script src="${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js"></script>
<script src="${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js"></script>
<!-- input 自动补全 -->
<script type="text/javascript" src="${contextPath}/static/statistics/js/jquery.autocomplete.js"></script>
<!-- form表单处理 -->
<script type="text/javascript" src="${contextPath}/static/franchisee/form.js"></script>

<style type="text/css">
    .customBtn {
        line-height: 20px;
        margin-bottom: 3px;
    }

    .btnLine {
        margin-left: 1px;
        margin-top: 8px;
        margin-bottom: 2px;
    }

    @-webkit-keyframes bouncedelay {
        0%, 80%, 100% {
            -webkit-transform: scale(0.0)
        }
        40% {
            -webkit-transform: scale(1.0)
        }
    }

    @keyframes bouncedelay {
        0%, 80%, 100% {
            transform: scale(0.0);
            -webkit-transform: scale(0.0);
        }
        40% {
            transform: scale(1.0);
            -webkit-transform: scale(1.0);
        }
    }

    .autocomplete-suggestions {
        border: 1px solid #999;
        background: #FFF;
        overflow: auto;
    }

    .autocomplete-suggestion {
        padding: 2px 5px;
        white-space: nowrap;
        overflow: hidden;
    }

    .autocomplete-selected {
        background: #F0F0F0;
    }

    .autocomplete-suggestions strong {
        font-weight: normal;
        color: #3399FF;
    }
	
    @-moz-document url-prefix() {
        fieldset {
            display: table-cell;
        }
    }

    .ui-jqgrid .ui-priority-secondary{
        background: #d5effc;
    }
    .bootstrap-select > .btn{
		color:#ABBAC3 !important;
		background-color: #fff !important;
		text-shadow:none;
		border-width:1px;
	}
	.bootstrap-select > .btn:hover, .bootstrap-select > .btn:focus:hover, .bootstrap-select > .btn.focus:hover, .bootstrap-select > .btn:active:hover, .bootstrap-select > .btn:focus:active, .btn-default:focus:active, .open > .btn.dropdown-toggle, .open > .btn-default.dropdown-toggle, .open > .btn.dropdown-toggle:hover, .open > .btn-default.dropdown-toggle:hover, .open > .btn.dropdown-toggle:focus, .open > .btn-default.dropdown-toggle:focus, .open > .btn.dropdown-toggle.focus, .open > .btn-default.dropdown-toggle.focus, .open > .btn.dropdown-toggle:active, .open > .btn-default.dropdown-toggle:active {
	    background-color: #fff !important;
	    border-color: #ABBAC3;
	}
	.layui-form-select{display:none};
    .ui-jqgrid .ui-jqgrid-title{font-size:12px;}    /*修改grid标题的字体大小*/

    .ui-jqgrid-sortable {font-size:12px;}   /*修改列名的字体大小*/

    .ui-jqgrid tr.jqgrow td {font-size:12px; font-family:"宋体"} /*修改表格内容字体*/

    /*****  表头样式  ******/
    /*.ui-jqgrid .ui-jqgrid-titlebar{*/
    /*background-color: #878787;*/
    /*height: 36px;*/
    /*}*/
    /*****  标题样式  ******/
    .ui-jqgrid-sortable {
        text-align: center;
    }

    #cb_grid-coupontype-table{
        margin-left: 9px;
    }
    #grid-coupontype-table_rn {
        width: 36px;
    }

    #myModal .modal-body table tr{
        height: 30px;
    }
    #myModal .modal-body table input[type='text']{
        height: 22px;
    }
    #myModal .modal-body table select {
        height: 22px;
    }

    .popover-content{
        color: red;
    }

    #cb_grid-stock-table{
        margin-left: 10px;
    }
    #cb_list2{
        margin-left: 10px;
    }

    label{
        font-size: 13px;
    }
	.unabled{
		color:grey;
	}
	.btn-default>.blue{
		color:grey !important;
	}
	.ui-jqgrid tr.footrow-ltr td {text-align:center}

	.container-horization-vertical {
		/*position: relative;*/
		text-align: center;
		/*width: 100%;*/
		/*height: 200px;*/
		/*background: deepskyblue;*/
		/*margin-bottom: 20px;*/
	}

	.container-horization-vertical-item1 {
		/*position: absolute;*/
		width: 135px;
		height: 30px;
		color: #FFFFFF;
		background: #BBBCBF;
		line-height: 30px;
		text-align: center;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		margin: auto;
	}

	.container-horization-vertical-item2 {
		/*position: absolute;*/
		width: 135px;
		height: 30px;
		color: #FFFFFF;
		background: #017457;
		line-height: 30px;
		text-align: center;
		top: 0;
		left: 0;
		bottom: 0;
		right: 0;
		margin: auto;
	}


	.inputfile {
		width: 0.1px;
		height: 0.1px;
		opacity: 0;
		overflow: hidden;
		/*position: absolute;*/
		z-index: -1;
	}

	.inputfile + label {
		font-size: 1.00em;
		font-weight: 700;
		color: white;
		padding: 4px;
		background-color: #3386b7;
		display: inline-block;
	}

	.inputfile:focus + label,
	.inputfile + label:hover {
		padding: 4px;
		background-color: #3392b7;
	}

	.inputfile + label {
		cursor: pointer; /* "hand" cursor */
	}

	.inputfile:focus + label {
		outline: 1px dotted #000;
		outline: -webkit-focus-ring-color auto 5px;
	}

	.inputfile + label * {
		pointer-events: none;
	}
</style>

<script>

    var uploadExcel = function () {

        var shopIds = $("#shopName").val()||-1;


        var excel = $("#file_input")[0].files[0];

        console.log(excel.name)
        console.log(excel)

        if (excel == undefined) {
            layer.msg("请选择excel文件")
            return
        }
        if (excel.name.substr(excel.name.lastIndexOf('.')) != '.xls' && excel.name.substr(excel.name.lastIndexOf('.')) != '.xlsx') {
            layer.msg("选择的文件不是excel类型")
            return
        }
        if (excel.size > 1048576) {
            layer.msg("选择的excel大于1Mb")
            return
        }

        var fm = new FormData();
        fm.append('excel', excel);
        fm.append('shopId', shopIds);
        layer.load(1)
        $.ajax(
            {
                url: '${contextPath}/ktCommon/saveExcelInstockOrder',
                type: 'POST',
                data: fm,
                contentType: false, //禁止设置请求类型
                processData: false, //禁止jquery对DAta数据的处理,默认会处理
                //禁止的原因是,FormData已经帮我们做了处理
                success: function (data) {
                    //测试是否成功
                    //但需要你后端有返回值
                    //console.log(data);
                    if (data.success) {
                        //console.log(data.data);
                        $('#getResultFileNameInput').val(data.data)
                        layer.msg('批量移库成功');
                        $(grid_stock_selector).trigger("reloadGrid");
                    } else {
                        layer.msg('批量移库失败，稍后再试');
                    }
                    layer.closeAll('loading')
                },
                error: function (error) {
                    layer.msg("网络连接失败");
                    layer.closeAll('loading')
                }
            }
        );
    }

</script>


<div class="row" id="app">
    <div class="row btnLine">
        <div class="button-len col-sm-12">
            <div class="form-inline layui-form ">
            	<div class="form-group">
                     <input type="text" class="form-control" id="productName" name="productName" placeholder="请输入商品名称">
                </div>
                <div class="form-group">
                     <div class="input-group ">
                        <input id="typeName" class="form-control" placeholder="选择商品类型" readonly/>
                        <input id="typeId" name="prodType" type="hidden" />
                        <input id="foreTypeName" name="foreTypeName" type="hidden" />
	                    <span class="input-group-btn">
		                     <div class="btn btn-primary btn-sm" onclick="javascript:$('#typeModal').modal('show');">
							选择
							</div>
	                    </span>
                       </div>                      		              
				</div>
           	 	<div class="form-group">
                     <select class="selectpicker" data-live-search="true" title="请选择店铺名称" data-live-search-placeholder="搜索" data-actions-box="true" id="shopName">
					</select>
					<input type="hidden" name="shopName" id="shopname" />
					<input type="hidden" name="shopIdName" id="shopIdName" />
                </div>
                <div class="form-group">
                    <button type="button" id="gridSave" class="btn btn-white btn-success btn-sm customBtn" >
                        <i class="ace-icon fa fa-plus blue"> 保存</i>
                    </button>

                </div>
				<div class="form-group">
					<div id="psearch" class="btn btn-sm btn-white btn-info search-len customBtn">
                        <i class="ace-icon fa fa-search orange"></i>查询
                    </div>
				</div>

				<div class="form-group">
					<label class="container-horization-vertical-item1" style="margin-left: 10px;"><a href="http://clouderp.skystorechain.com:20080/web/execl/Excel移库模块.xls">模版下载</a></label>
				</div>
				<%--<div class="container-horization-vertical">--%>
				<div class="form-group">
					<label class="container-horization-vertical" style="margin-left: 5px;">
						<%--<input type="file" name="excelInput">--%>
						<input type="file" name="excelInput" id="file_input" class="inputfile"/>
						<label id="file_input_label" style="margin-top: 9px; height: 29px" for="file_input"><i class="ace-icon fa fa-folder-open"></i> 请选择Excel文件</label>
					</label>
				</div>
					<%--<label style="margin-left: 10px;" id="file_input_label" for="file_input"><i class="ace-icon fa fa-folder-open"></i> 请选择Excel文件</label>--%>
					<div style="margin-left: 5px;" class="btn btn-sm btn-white btn-info search-len customBtn" onclick="uploadExcel()">
						<i class="ace-icon fa fa-search orange"></i>导入Excel移库
					</div>
				</div>

            </form>
        </div>
    </div>
    <br/>
    <!-- 内容数据开始 -->
    <div class="col-xs-12">
        <table id="grid-stock-table"></table>

        <div id="grid-stock-pager"></div>

    </div>
    <!-- 内容数据结束 -->

</div>
<div id="typeModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="typeModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
						&times;
					</button>
					<h4 class="modal-title" id="typeModalLabel">
						选择商品类型
					</h4>
				</div>
				<div class="modal-body">
					<ul id="typetree" class="ztree">
					</ul>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-primary" onclick="javascript:selectedTypes()">
						确认
					</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">取消
					</button>
				</div>
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
		</div>
<!-- 公用变量 -->
<script type="text/javascript">
    var lastSel;//在顶部定义
    var grid_stock_selector = "#grid-stock-table";
    var pager_stock_selector = "#grid-stock-pager";

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

    var laypage = layui.laypage,
        layer = layui.layer
    laydate = layui.laydate;

</script>

<!-- 方法调用（业务） -->


<!-- jqGrid 公用方法 -->
<script type="application/javascript">
	
    //重新加载数据
/*     var reload = function () {
        var filters = {};
        filters.shopId = $('#shopId').val();
        filters.date = $('#date').val();

        $(grid_stock_selector).jqGrid('setGridParam',{
            url:"${contextPath}/ktTakeStock/getKtProdMove",
            datatype:'json',
            postData: filters,
        }).trigger("reloadGrid"); //重新载入
    } */
    
</script>

<!-- jqGrid加载数据 -->
<script type="text/javascript">
    var scripts = [null, "${contextPath}/static/ace/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.js", "${contextPath}/static/ace/components/jqGrid/js/jquery.jqGrid.js", "${contextPath}/static/ace/components/jqGrid/js/i18n/grid.locale-cn.js", "${contextPath}/static/layer/layer.js","${contextPath}/static/ztree/js/jquery.ztree.core-3.5.js", "${contextPath}/static/ztree/js/jquery.ztree.excheck-3.5.js", null]
    var lastsel,INDEXSEL = -1,RECSAVE = new Array();
    function getShop(){
    	$.ajax({
            url: '${contextPath}/ktcount/getShops', //localhost:8080
            data:{"zoneCode":"","shopType":"\'中深\'"},
            type: 'post',
            success: function (data) {
               	var data = data.data;
    			var html = '';
            	for(var i = 0;i < data.length;i++){
            		html +='<option value="'+data[i]["shopId"]+'">'+data[i]["shopName"]+'</option>';
            	}
            	$("#shopName").html(html);
            	$('#shopName').selectpicker('refresh');
            	if(!("" == data || null == data)){
            		$("#shopName").selectpicker('val',data[0]["shopId"]);
            	}
            	getKtProdMoves();
            },
            error: function (error) {
                alert(error)
            }
        })
    }
    function getProdType(){
    	$.ajax({
            url: '${contextPath}/ktcount/getProdTypes', //localhost:8080
            type: 'post',
            success: function (data) {
                var orginTypes = data.data;
                var setting = {
                        check: {
                            enable: true,
                            chkStyle: "checkbox",
                        },
                        data: {
                            simpleData: {
                                enable: true,
                                idKey: "TYPE_ID",
                                pIdKey: "PARENT_ID",
                                rootPId: ''
                            },
                            key: {
                                name: "TYPE_NAME"
                            },
                        }
                    };
    	            
                    $.fn.zTree.init($("#typetree"), setting, orginTypes);
      
            },
            error: function (error) {
                alert(error)
            }
        })
    }
    var getKtProdMoves = function (shopId) {
        var filters = {};
        filters.limit = 10000;
        filters.offset = 0;
        filters.shopName=$("#shopName").val()||-1;
        filters.productName = $("#productName").val().trim();
        $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
            jQuery(function ($) {
                jQuery(grid_stock_selector).jqGrid({
                    url: "${contextPath}/ktTakeStock/getKtProdMove",
                    datatype: "json",
                    postData: filters,
                    mtype: 'POST',
                    height: 500,
                    colNames : ['SEQ_ID','简码','商品名称','单位', '零售价', '库存总数', '仓库存量', '商场存量','转出率', '仓库转出'],
                    colModel : [
                        {
                            name: 'SEQ_ID',
                            index: 'SEQ_ID',
                            editable: false,
                            sortable: false,
                            hidden: true,
                            editrules: {required: true}
                        },
                        {
                            name: 'SHORT_CODE',
                            index: 'SHORT_CODE',
                            editable: false,
                            sortable: true,
                            editrules: {required: true}
                        },
                        {
                            name: 'PRODUCT_NAME',
                            index: 'PRODUCT_NAME',
                            editable: false,
                            sortable: false,
                            editrules: {required: true}
                        },{
                            name: 'UNIT',
                            index: 'UNIT',
                            editable: false,
                            sortable: false,
                            editrules: {required: true}
                        },
                        {
                            name: 'RTL_PRICE',
                            index: 'RTL_PRICE',
    //                        width: 60,
                            editable: false,
                            sortable: false,
                            editrules: {required: true}
                        },
                        {
                            name: 'STOCK',
                            index: 'STOCK',
    //                        width: 60,
                            editable: false,
                            dataType: 'int',
                            sortable: true,
                            editrules: {required: true}
                        ,formatter: function (v, x, r) {
                                if(v < 0)
                                    return '<span style="color:red">'+v+'</span>'
                                  return v;
                          }
                        },
                        {
                            name: 'REPOSITORY_STOCK',
                            index: 'REPOSITORY_STOCK',
    //                        width: 30,
                            editable: false,
                            sortable: true,
                            formatter: function (v, x, r) {
                                var stock = r.STOCK - r.SHOP_STOCK;
                                if (stock < 0){
                                    v = 0;
								} else {
                                    v = stock;
								}
                                if(v < 0)
                                    return '<span style="color:red">'+v+'</span>'
                            return v.toFixed(0);
                          }
                        },
                        {
                            name: 'SHOP_STOCK',
                            index: 'SHOP_STOCK',
    //                        width: 60,
                            editable: false,
                            sortable: true,
                            formatter: function (v, x, r) {
                                if(v < 0)
                                    return '<span style="color:red;font-weight:bold">'+v+'</span>'
                            return v;
                            }
                        },
                        {
                            name: 'TRATE',
                            index: 'TRATE',
                            hidden: true,
                            editable: false,
                            sortable: false
                        },
                        {name : 'tranferStock',index : 'tranferStock', editable: true,edittype:"text", align: 'center',
                            
                        },
                    ],
                    sortname: 'STOCK', //设置默认的排序列
                    sortorder: 'asc',
                    footerrow:true,
                    rownumbers: true, //自动行数
                    autowidth:true,  //宽度自适应
                    viewrecords: true,
                    multiselect: true,//复选框  
                    rowNum : 1000000,//一页显示多少条
                    caption: "商品移库",
                    onSelectRow :function(rowid,status){
                    	if(!status){
                    		$(grid_stock_selector).jqGrid("restoreRow",rowid,null);
                    		RECSAVE[rowid] = undefined;
                    	}
                    	var rowData = $(grid_stock_selector).jqGrid('getRowData', rowid) 
                    	if (status && rowid) {
                    		jQuery(this).jqGrid('editRow', rowid, true);
                    		$('input[name="tranferStock"]').unbind('input propertychange').bind('input propertychange',tschange)
                    		lastsel = rowid;                    		
                    	}
                    	INDEXSEL = rowid;
                    	tschange();
                    },loadComplete: function (data) {
                    	var reccount = $(this).jqGrid('getGridParam', 'reccount');
                    	RECSAVE = new Array(reccount);
                    	$("#grid-stock-table_rn").html(data.length);
                    	var sum_1 = $(this).getCol('STOCK', false, 'sum');
                    	var sum_2 = $(this).getCol('REPOSITORY_STOCK', false, 'sum');
                    	var sum_3 = $(this).getCol('SHOP_STOCK', false, 'sum');
                    	$(this).footerData('set',{'rn':"合计",'STOCK': sum_1.toFixed(2),'REPOSITORY_STOCK': sum_2.toFixed(2),'SHOP_STOCK': sum_3.toFixed(2)});
                    }
                });
				$("#gridSave").bind('click',function(){
					saveData();
				});
 				 $("#psearch").bind('click',function(){
 					 var filters = {};
                     filters.limit = 10000;
                     filters.offset = 0;
                     filters.shopName=$("#shopName").val()||-1;
                     filters.productName = $("#productName").val().trim();
                     filters.prodType = $("#typeId").val().trim();
                     jQuery(grid_stock_selector).jqGrid('setGridParam', {
                         postData: filters
                     }).trigger("reloadGrid");
                     $(".ui-jqgrid-ftable").find("td:last").html("");
				} )
                $(window).triggerHandler('resize.jqGrid');//trigger window resize to make the grid get the correct size

                $("#jqgh_grid-coupontype-table_rn").html('');
                $("#grid-coupontype-table_rn").css('width', '36px');
            });
        });
    }
    document.onkeydown = function(e){
        var ev = document.all ? window.event : e;
        if(ev.keyCode==13) {
        	var transStockNum = $("#"+INDEXSEL+"_tranferStock").val();
        	if(transStockNum == "" || isNaN(transStockNum)){
                layer.closeAll('loading');
                layer.msg('提示：请正确输入转仓数量',{icon:0})
                return;
            }
        	var rowData = $(grid_stock_selector).jqGrid('getRowData', INDEXSEL); 
        	if(rowData["REPOSITORY_STOCK"]!=0){
        		RECSAVE[INDEXSEL] = 1;
        		upDownKeyFunc(1);
        	}else{
        		layer.confirm('仓库存量为0，确定移库吗？', {
        			  btn: ['确定','取消'] //按钮
        			}, function(){
        				RECSAVE[INDEXSEL] = 1;
        				layer.closeAll();
        				upDownKeyFunc(1);
        			}, function(){
        				upDownKeyFunc(1);
        		});
        	} 
        	
        }else if(ev.keyCode == 38){
        	upDownKeyFunc(-1);
        }else if(ev.keyCode == 40){
        	upDownKeyFunc(1);
        }
    }
    var upDownKeyFunc = function(factor){
    	var curIsSel = $("#jqg_grid-stock-table_"+(INDEXSEL)).prop("checked");
    		INDEXSEL = parseInt(INDEXSEL) + factor;
    	var isSel = $("#jqg_grid-stock-table_"+INDEXSEL).prop("checked");
    	if(RECSAVE[INDEXSEL+factor*-1]==1){
    		isSel || $(grid_stock_selector).jqGrid('setSelection',INDEXSEL,true);
    	}else{
    		$(grid_stock_selector).jqGrid("restoreRow",INDEXSEL+factor*-1,null);
    		$(grid_stock_selector).jqGrid('setSelection', INDEXSEL+factor*-1,false);
    		if(RECSAVE[INDEXSEL]!=1 && !isSel)
    			$(grid_stock_selector).jqGrid('setSelection', INDEXSEL,true);
    	}
    }
    var saveData = function(){
    	var ids = $(grid_stock_selector).jqGrid('getGridParam', 'selarrrow');
        if(ids.length == 0){
            layer.closeAll('loading');
            layer.msg('提示：请选择商品',{icon:0})
            return;
        }
        var params = [];
        for(var i = 0;i < ids.length;i++){
        	var rowData = $(grid_stock_selector).jqGrid('getRowData', ids[i]);	
        	var param = {};
        	if($("#"+ids[i]+"_tranferStock").val() == "" || isNaN($("#"+ids[i]+"_tranferStock").val())){
        		if(i < (ids.length-1)){
		        	layer.closeAll('loading');
		            layer.msg('提示：第'+ids[i]+'条,请输入仓库转出量',{icon:0})
		            return;
        		}
	        }
        	param["seqId"] = rowData["SEQ_ID"];
        	param["tranferStock"] = $("#"+ids[i]+"_tranferStock").val();
        	param["tRate"] = rowData["TRATE"];
        	params.push(param);
        }
        if($("#gridSave").hasClass("btn-default")){
        	layer.closeAll('loading');
            layer.msg('正在提交,请稍后...',{icon:0})
    		return;
    	}
    	$("#gridSave").removeClass("btn-success").addClass("btn-default");
	       $.ajax({
	            url: '${contextPath}/ktTakeStock/saveKtProdMove',
	            type: 'post',
	            data: {"params":JSON.stringify(params)},
	            success: function (data) {
	                layer.msg('提示：转仓成功',{icon:0});
        			$(grid_stock_selector).trigger("reloadGrid");
        			$("#gridSave").removeClass("btn-default").addClass("btn-success");
        			$(".ui-jqgrid-ftable").find("td:last").html("");
	            },
	            error: function (error) {
	                layer.closeAll('loading');
	                $("#gridSave").removeClass("btn-default").addClass("btn-success");
	            }
	        })
    }
    function selectedTypes(){
   	 $("#typeModal").modal('hide')
      var zTree = $.fn.zTree.getZTreeObj("typetree");
      var nodes = zTree.getCheckedNodes();
      var typeNameVal = "",typeIdVal = "",foreTypeNameVal = "";
      for(var i = 0,nodesLen = nodes.length;i < nodesLen;i++){
     	 if(!nodes[i]["isParent"]){
   	    	 typeNameVal += nodes[i]["TYPE_NAME"]+",";
   	    	 typeIdVal += nodes[i]["TYPE_ID"]+",";
     	 }
     	 if(nodes[i]["level"] == 1){
     		 foreTypeNameVal += nodes[i]["TYPE_NAME"]+",";
     	 }
      }
      if(nodes.length > 0){
     	 typeNameVal = typeNameVal.substring(0,typeNameVal.length-1);
     	 typeIdVal = typeIdVal.substring(0,typeIdVal.length-1);
     	 foreTypeNameVal = foreTypeNameVal.substring(0,foreTypeNameVal.length-1);
      }
      $("#typeName").val(typeNameVal)
      $("#typeId").val(typeIdVal)
      $("#foreTypeName").val(foreTypeNameVal)
   }
   function tschange(){
	   var ids = $(grid_stock_selector).jqGrid('getGridParam', 'selarrrow');
	   var sum = 0;
	   for(var i = 0;i <ids.length;i++){
		   var rowData = $(grid_stock_selector).jqGrid('getRowData', ids[i]);	
		   var sval = $("#"+ids[i]+"_tranferStock").val() || 0;
		   sum += parseFloat(sval);
	   }
	   $(".ui-jqgrid-ftable").find("td:last").html(sum);
   } 
</script>

<script type="text/javascript">
	$(function(){
		getProdType();
		 getShop();
	})
   
</script>